﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using tracker.Models.DTO;
using tracker.Models;
using tracker.Models.DAL;
using System.Collections.Generic;

namespace tracker.Models.BLL
{
    public class AlarmDefineBLL : ErpCatalogueBaseBL
    {
        #region STORE DEFINE
        public const string STORE_INSERT = "AlarmDefine_Insert";
        public const string STORE_UPDATE = "AlarmDefine_Update";
        public const string STORE_DELETE = "AlarmDefine_Delete";
        public const string STORE_SELECT_ALL = "AlarmDefine_GetAll";
        #endregion

        #region Methods
        /// <summary>
        /// Hàm này thêm mới một ROW thông qua 1 mảng tham số và 1 mảng giá trị với tham số
        /// </summary>
        /// <param name="arrParamName">Array of Parameters</param>
        /// <param name="arrParamValue">Array of Values</param>
        /// <returns>string</returns>
        public static string InsertERP(string[] arrParamName, object[] arrParamValue)
        {
            string strReturn = "0";
            strReturn = Insert(STORE_INSERT, arrParamName, arrParamValue);
            return strReturn;
        }

        /// <summary>
        /// Hàm này update một ROW thông qua 1 mảng tham số và 1 mảng giá trị với tham số
        /// </summary>
        /// <param name="arrParamName">Array of Parameters</param>
        /// <param name="arrParamValue">Array of Values</param>
        /// <returns></returns>
        public static string UpdateERP(string[] arrParamName, object[] arrParamValue)
        {
            string strReturn = "0";
            strReturn = Update(STORE_UPDATE, arrParamName, arrParamValue);
            return strReturn;
        }

        /// <summary>
        /// Hàm này delete ROW thông qua 1 mảng tham số và 1 mảng giá trị với tham số
        /// </summary>
        /// <param name="arrParamName">Array of Parameters</param>
        /// <param name="arrParamValue">Array of Values</param>
        /// <returns></returns>
        public static string DeleteERP(string[] arrParamName, object[] arrParamValue)
        {
            string strReturn = "0";
            strReturn = Delete(STORE_DELETE, arrParamName, arrParamValue);
            return strReturn;
        }

        /// <summary>
        /// Hàm này trả về danh sách các row theo điều kiện đầu vào
        /// </summary>
        /// <param name="arrParamName">Array of Parameters</param>
        /// <param name="arrParamValue">Array of Values</param>
        /// <returns></returns>
        public static DataSet SelectAll(string[] arrParamName, object[] arrParamValue)
        {
            DataSet ds = new DataSet();
            ds = SelectAllWithParameter(STORE_SELECT_ALL, arrParamName, arrParamValue);
            return ds;
        }
        #endregion
        /*
        public static int Insert(EAlarmDefine OAlarmDefine)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[1] = new SqlParameter(@"AlarmType", OAlarmDefine.AlarmType);
            pr[2] = new SqlParameter(@"Expression", OAlarmDefine.Expression);
            //   pr[3] = new SqlParameter(@"Id", OAlarmDefine.DefineID);
            pr[0] = new SqlParameter(@"CreateBy", OAlarmDefine.CreateBy);

            return SqlHelper.insertNewIDExecuteNonQuery(CommandType.Text, "Insert into AlarmDefine([AlarmType],[Expression],[CreateBy]) values(@AlarmType,@Expression,@CreateBy)", "AlarmDefine", pr);
        }
        public static int Update(EAlarmDefine OAlarmDefine)
        {
            SqlParameter[] pr = new SqlParameter[5];
            pr[1] = new SqlParameter(@"AlarmType", OAlarmDefine.AlarmType);
            pr[2] = new SqlParameter(@"Expression", OAlarmDefine.Expression);
            pr[3] = new SqlParameter(@"Id", OAlarmDefine.DefineID);
            pr[0] = new SqlParameter(@"ModifyBy", OAlarmDefine.ModifyBy);
            pr[4] = new SqlParameter(@"CreateBy", OAlarmDefine.CreateBy);

            return SqlHelper.iExecuteNonQuery(CommandType.Text, "Update AlarmDefine set [AlarmType]=@AlarmType,[Expression]=@Expression,[ModifyBy]=@ModifyBy,ModifyDate=getdate() where id=@Id AND CreateBy=@CreateBy", pr);
        }
        public static int Delete(string DefineIDs, string _Username)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"CreateBy", _Username);
            return SqlHelper.iExecuteNonQuery(CommandType.Text, "delete AlarmDefine where id IN (" + DefineIDs + ") AND CreateBy=@CreateBy", pr);
        }
        public static DataTable Select(string _Username)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"CreateBy", _Username);
            return SqlHelper.ExecuteData(CommandType.Text, "Select * from AlarmDefine where CreateBy=@CreateBy", pr);
        }
        public static string getAlarmNameByAlarmCode(string _Username, string AlarmCode)
        {
            string strReturn = null;
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"CreateBy", _Username);
            pr[1] = new SqlParameter(@"AlarmType", AlarmCode);

            DataTable dt = SqlHelper.ExecuteData(CommandType.Text, "Select top 1 * from AlarmDefine where CreateBy=@CreateBy AND AlarmType=@AlarmType", pr);
            if (dt.Rows.Count > 0)
            {
                strReturn = dt.Rows[0]["Expression"].ToString();
                dt.Dispose();
            }
            return strReturn;
        }
         * */
    }
}
